'use strict';

const Controller = require('egg').Controller;

class ComController extends Controller {
    async dowCom() {
        const { ctx } = this;
        const results = await this.app.mysql.select('article');
        ctx.body = {
            code: 200,
            results
        }
    }
    async Comlist() {
        const { ctx } = this;
        const results = await this.app.mysql.select('comment');
        ctx.body = {
            code: 200,
            results
        }
    }
    async addList() {
        const { ctx } = this;
        const { users,value } = ctx.request.body
        console.log(ctx.request.body)
        const result = await this.app.mysql.query(`INSERT INTO comment (user, word, time, id) VALUES ('${users}','${value}', '2021-12-23', NULL);`);
        if (result.length) {
            ctx.body = {
                code: 200,
                mes: "添加成功"
            }
        } else {
            ctx.body = {
                code: 302,
                mes: "添加失败"
            }
        }
    }
}

module.exports = ComController;
